<template lang="pug">
  .page.home-page
    template(v-if="isAdmin")
      homeAdmin
    template(v-if="isHro")
      homeHro
    template(v-if="isCustomer")
      homeCustomer
    bulletin(ref="bulletinModal" :bulletinData="bulletinData" :spinShow="spinShow" :bulletinId="bulletinId")
</template>

<script>
import homeAdmin from './home_admin.vue'
import homeHro from './home_HRO.vue'
import homeCustomer from './home_customer_202105.vue'
import bulletin from './modal/bulletin.vue'
import BulletinApi from '@/api/Bulletin.api.js'
import { SysAreaApi } from '@/api/SysArea.api.js'
import { BusinessDocumentApi } from '@/api/BusinessDocument.api.js'
import { mapActions } from 'vuex'

export default {
  name: '',
  components: {
    homeAdmin,
    homeHro,
    homeCustomer,
    bulletin
  },
  data () {
    return {
      adminStatus: [8, 32], // admin工作台
      hroStatus: [4], // hro工作台
      customerStatus: [0, 1, 2, 16], // 客户工作台
      userStatus: null, // 当前用户角色状态码
      spinShow: true,
      bulletinId: '',
      bulletinData: {} // 公告数据
    }
  },
  computed: {
    isAdmin () {
      return this.adminStatus.indexOf(this.userStatus) > -1
    },
    isHro () {
      return this.hroStatus.indexOf(this.userStatus) > -1
    },
    isCustomer () {
      return this.customerStatus.indexOf(this.userStatus) > -1
    }
  },
  mounted () {
    // this.getBusinessDocumentList()
    this.getUserBulletin()
    
  },
  methods: {
    getUserBulletin () {
      BulletinApi.GetUserBulletin({
        UserID: JSON.parse(localStorage.getItem('clientLoginInfo')).data.userId
      }).then(res => {
        if (res.data.success) {
          this.bulletinId = res.data.data.id
          this.$refs.bulletinModal.show()
          BulletinApi.GetBulletin({
            id: this.bulletinId
          }).then(content => {
            this.bulletinData = content.data.data
            this.spinShow = false
          })
        } else {
          return false
        }
      })
    }
    // ...mapActions([
    //   'handleSetECMWarnCount'
    // ]),

    // // 获取企业证件管理提示
    // async getBusinessDocumentList () {
    //   var params = {
    //     HasPaging: true,
    //     PageIndex: 1,
    //     PageSize: 10
    //   }
    //   let res = await BusinessDocumentApi.getList({ ...params, ...this.formData })
    //   console.log('🧞‍ 获取企业证件管理提示res: ', res)
    //   if (res.status === 200 && res.data.success) {
    //     this.handleSetECMWarnCount(res.data.warnCount)
    //   } else {
    //   }
    //   this.loading = false
    // },
  },
  created () {
    let infoData = JSON.parse(localStorage.getItem('clientLoginInfo'))
    this.userStatus = infoData.data.dataAccessRoleType
  }
}
</script>
<style lang="less">
  @import './home.less';
</style>
<style lang="less" scoped>
  .home-page{
    padding: 15px;
  }
</style>
